<template>
  <div :class="{'hidden':hidden}" class="pagination-container">
    <el-pagination
      :background="background"
      :current-page.sync="currentPage"
      :page-size.sync="pageSize"
      :layout="layout"
      :page-sizes="pageSizes"
      :total="total"
      v-bind="$attrs"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import { scrollTo } from '@/utils/scroll-to'

export default {
  name: 'Pagination',
  props: {
    total: {
      required: true,
      type: Number
    },
    page: {
      type: Number,
      default: 1
    },
    limit: {
      type: Number,
      default: 20
    },
    pageSizes: {
      type: Array,
      default() {
        return [10, 20, 30, 50]
      }
    },
    layout: {
      type: String,
      default: ' prev, pager, next, jumper'
      // total, sizes,
    },
    background: {
      type: Boolean,
      default: true
    },
    autoScroll: {
      type: Boolean,
      default: true
    },
    hidden: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    currentPage: {
      get() {
        return this.page
      },
      set(val) {
        this.$emit('update:page', val)
      }
    },
    pageSize: {
      get() {
        return this.limit
      },
      set(val) {
        this.$emit('update:limit', val)
      }
    }
  },
  methods: {
    handleSizeChange(val) {
      this.$emit('pagination', { page: this.currentPage, limit: val })
      if (this.autoScroll) {
        scrollTo(0, 800)
      }
    },
    handleCurrentChange(val) {
      this.$emit('pagination', { page: val, limit: this.pageSize })
      if (this.autoScroll) {
        scrollTo(0, 800)
      }
    }
  }
}
</script>

<style scoped>
.pagination-container {
  background: #002127;
  padding: 32px 16px;
}
.pagination-container.hidden {
  display: none;
}
/*未选中*/
::v-deep .el-pagination .btn-next,
::v-deep .el-pagination .btn-prev,
::v-deep.el-pagination.is-background .el-pager li {
    background-color: rgba(0,231,231,0.051);
    border-radius: 1px 1px 1px 1px;
    border: 1px solid rgba(0,231,231,0.102);
    color: rgba(0,231,231,0.5);
}
/* 选中框*/
::v-deep.el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: rgba(0,231,231,0.149);
  border-radius: 1px 1px 1px 1px;
  border: 1px solid #00E7E7;
  color: #00E7E7;
}
/*鼠标经过*/
::v-deep.el-pagination.is-background .el-pager li:not(.disabled):hover {
  background-color: rgba(0,231,231,0.149);
  border-radius: 1px 1px 1px 1px;
  border: 1px solid #00E7E7;
  color: #00E7E7;
}
/*文字颜色*/
::v-deep.el-pagination.is-background .el-pagination__jump {
  color: #ffffff;
}
/*分页input*/
::v-deep input.el-input__inner {
  background: rgba(0,231,231,0.051);
  border-radius: 1px 1px 1px 1px;
  color: #ffffff;
  border: 1px solid rgba(0,231,231,0.302);
}

</style>
